package cn.com.zcode.exam.service;

import java.util.List;

import cn.com.zcode.core.service.BaseServiceSupport;
import cn.com.zcode.email.service.EmailService;
import cn.com.zcode.exam.dao.ExamDao;
import cn.com.zcode.exam.model.Answer;
import cn.com.zcode.exam.model.Examination;
import cn.com.zcode.exam.model.PQConnector;
import cn.com.zcode.exam.model.Paper;
import cn.com.zcode.exam.model.Question;
import cn.com.zcode.exam.model.StaticInfo;
import cn.com.zcode.exam.model.Wrong;

public class ExamServiceImpl extends BaseServiceSupport<ExamDao> implements ExamService {

	
	
	@Override
	public Question addQuestion(Question question) {
		if (question != null) {
			mainDao.saveQuestion(question);
			mainDao.save(new PQConnector(question.getId(), question.getPaper().getId()));
		}
		return question;
	}

	@Override
	public Question updateQuestion(Question question) {
		if (question != null) {
			mainDao.saveOrUpdate(question);
		}
		return question;
	}

	@Override
	public List<Question> findQuestions(String pmp) {
		return mainDao.findQuestions(pmp);
	}

	@Override
	public Paper getPaper(String pid) {

		return mainDao.getPaper(pid);
	}

	@Override
	public Paper addPaper(Paper paper) {
		return mainDao.save(paper);
	}

	@Override
	public Answer addAnswer(Answer answer) {
		return mainDao.save(answer);
	}

	@Override
	public Examination addExamination(Examination examination) {
		return mainDao.save(examination);

	}

	@Override
	public Wrong addWrong(Wrong wrong) {
		return mainDao.save(wrong);

	}

	@Override
	public List<Paper> findPapers(String key, String userid) {
		return mainDao.findPapers(key, userid);
	}

	@Override
	public Wrong getWrong(String userId, String questionId) {

		return mainDao.getWrong(userId, questionId);
	}

	@Override
	public List<Question> findWrongQuestions(String type, String userId) {
		List<Question> list = mainDao.findWrongQuestions(type, userId);
		return list;
	}

	@Override
	public List<StaticInfo> getStatinfo(String string) {
		return mainDao.findStatinfo(string);
	}

	@Override
	public Paper getPaper(String type, String title, int state, String userid) {

		return mainDao.getPaper(type, title, state, userid);
	}

	@Override
	public Paper mergePaper(Paper paper) {

		return mainDao.merge(paper);
	}

	@Override
	public List<StaticInfo> getPaperInfo(String type) {

		return mainDao.getPaperInfo(type);
	}

	@Override
	public List<Question> searchQuestions(String keyword, String userId) {

		return mainDao.searchQuestions(keyword, userId);
	}

	@Override
	public Question getQuestion(String id) {
		return mainDao.getQuestion(id);
	}

	@Override
	public List<Examination> findExamination(String key, String userid) {
		return mainDao.findExamination(key, userid);
	}

	@Override
	public List<Question> findNewExamQuestions(String pid) {

		return mainDao.findNewExamQuestions(pid);
	}

	@Override
	public List<Question> findLastExamQuestions(String eid) {

		return mainDao.findLastExamQuestions(eid);
	}

	@Override
	public void saveFinishExamination(String eid) {
		mainDao.saveFinishExamination(eid);
	}


}
